// 指令本质上也是一个对象 {}
export default {
  // bind  指令绑定到元素上时执行   接收两个参数 el，是绑定的元素，   binding，是指令的信息
  bind: function(el, binding) {
    const options = binding.value;
    const { className, activeClass, currentIndex } = options;
    const children = el.getElementsByClassName(className);
    children[currentIndex].className += ` ${activeClass}`;
  },
  update: function(el, binding) {
    const oldOptions = binding.oldValue;
    const { currentIndex: oldCurIndex } = oldOptions;
    const options = binding.value;
    const { className, activeClass, currentIndex } = options;
    const children = el.getElementsByClassName(className);
    children[currentIndex].className += ` ${activeClass}`;
    children[oldCurIndex].className = `${className}`;
  }
};
